<?php

namespace App\Http\Controllers\Kms\Backend\App;

use App\Http\Controllers\Kms\Backend\BackendBaseController;
use App\Http\Validate\Kms\Clients\ClientsValidate;
use App\Http\Validate\Kms\Clients\ClientsVersionValidate;
use App\Service\Kms\App\ClientService;
use App\Service\Kms\App\ClientVersionService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class ClientVersionController extends BackendBaseController
{
    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function list(Request $request): JsonResponse
    {
        $params = ClientsVersionValidate::listValidate($request->all());
        return $this->success(ClientVersionService::list($params));
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function addVersion(Request $request): JsonResponse
    {
        $params = ClientsVersionValidate::addVersionValidate($request->all());
        ClientVersionService::addVersion($params);
        return $this->success();
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function updateVersion(Request $request): JsonResponse
    {
        $params = ClientsVersionValidate::updateVersionValidate($request->all());
        ClientVersionService::updateVersion($params);
        return $this->success();
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function delete(Request $request): JsonResponse
    {
        $params = ClientsVersionValidate::deleteVersionValidate($request->all());
        ClientVersionService::deleteVersion($params);
        return $this->success();
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function releaseVersion(Request $request): JsonResponse
    {
        $params = ClientsVersionValidate::releaseVersionValidate($request->all());
        ClientVersionService::releaseVersion($params);
        return $this->success();
    }
}
